﻿using DtoFw;
using DtoFw.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SceneEvidenceAPI.Controllers
{
    /// <summary>
    /// 物证盘点
    /// </summary>
    [Route("api/v2/handheld")]
    public class PanDianController : BaseController
    {
        private readonly CasePhysicalPanDianService _casePhysicalPanDianService;
        public PanDianController(CasePhysicalPanDianService casePhysicalPanDianService)
        {
            this._casePhysicalPanDianService = casePhysicalPanDianService;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public BaseResult Post([FromBody]BaseQuery reqDto)
        {
            return _casePhysicalPanDianService.Post(reqDto);
        }
        /// <summary>
        /// 盘点计划查询
        /// </summary>
        /// <param name="reqDto"></param>
        /// <returns></returns>
        [HttpPost("pager")]
        public BaseGenericResult<object> QueryList([FromBody] CaseQueryDto reqDto)
        {
            return BaseGenericResult<object>.Succeed(_casePhysicalPanDianService.QueryList(reqDto));
        }
        /// <summary>
        /// 盘点计划详细
        /// </summary>
        /// <param name="reqDto"></param>
        /// <returns></returns>
        [HttpGet("pandiandetail")]
        public BaseGenericResult<object> QueryPanDianDetail([FromQuery] CaseQueryDto reqDto)
        {
            return BaseGenericResult<object>.Succeed(_casePhysicalPanDianService.QueryPanDianDetail(reqDto));
        }
        /// <summary>
        /// 盘点计划详细
        /// </summary>
        /// <param name="reqDto"></param>
        /// <returns></returns>
        [HttpPost("deletePanDianTask")]
        public BaseGenericResult<object> DeletePanDianTask([FromBody] BaseQuery ids)
        {
            return BaseGenericResult<object>.Succeed(_casePhysicalPanDianService.DeletePanDianTask(ids));
        }
        #region 盘点任务

        /// <summary>
        /// 上报结果
        /// </summary>
        [HttpPost("task/report")]
        [AllowAnonymous]
        public object Report(List<PanDianTaskEntity> lst)
        {
            var r = _casePhysicalPanDianService.PanDianReport(lst);
            return new { success = true, msg = "", data = r };
        }
        /// <summary>
        /// 获取盘点任务信息
        /// </summary>
        [Route("tasks")]
        [AllowAnonymous]
        public object GetTasks(string organid)
        {
            if (string.IsNullOrEmpty(organid))
            {
                return new { success = false, msg = "缺少单位id" };
            }

            var tasks = _casePhysicalPanDianService.GetTasks(long.Parse(organid));
            return new { success = true, msg = "", data = tasks };
        }


        #endregion 盘点任务

    }
}
